package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.CustomerCountTwoVo;
import com.ruoyi.common.core.domain.entity.CustomerCountVo;
import com.ruoyi.common.core.domain.entity.CustomerInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ICustomerInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户数据Controller
 *
 * @author ruoyi
 * @date 2025-03-09
 */
@RestController
@RequestMapping("/system/customerData")
public class CustomerInfoController extends BaseController
{
    @Autowired
    private ICustomerInfoService customerInfoService;

    /**
     * 查询客户数据列表
     */
//    @PreAuthorize("@ss.hasPermi('system:customerData:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerInfo customerInfo)
    {
        startPage();
        List<CustomerInfo> list = customerInfoService.selectCustomerInfoList(customerInfo);
        return getDataTable(list);
    }



    @GetMapping("/listPermissionPage")
    public TableDataInfo listPermissionPage(CustomerInfo customerInfo)
    {
        startPage();
        List<CustomerInfo> list = customerInfoService.selectCustomerInfoListPage(customerInfo);
        return getDataTable(list);
    }
    @GetMapping(value = "/getById/{id}")
    public AjaxResult getById(@PathVariable("id") Long id)
    {
        return success(customerInfoService.selectCustomerInfoByIdAn(id));
    }


    @GetMapping("/listPermissionZong")
    public AjaxResult listPermissionZong(CustomerInfo customerInfo)
    {
//        startPage();
        List<CustomerCountVo> list = customerInfoService.selectCustomerInfoListZong(customerInfo);
        return AjaxResult.success(list);
    }
// 行业
    @GetMapping("/selectCustomerIndustry")
    public AjaxResult selectCustomerIndustry(CustomerInfo customerInfo)
    {
//        startPage();
        List<CustomerCountVo> list = customerInfoService.selectCustomerInfoListIndustry(customerInfo);
        return AjaxResult.success(list);
    }
// 产品
    @GetMapping("/selectCustomerProduct")
    public AjaxResult selectCustomerProduct(CustomerInfo customerInfo)
    {
//        startPage();
        List<CustomerCountTwoVo> list = customerInfoService.selectCustomerInfoListProduct(customerInfo);
        return AjaxResult.success(list);
    }
//   阻碍因素
    @GetMapping("/selectCustomerHindrances")
    public AjaxResult selectCustomerHindrances(CustomerInfo customerInfo)
    {
//        startPage(); selectCustomerHindrances
        List<CustomerCountTwoVo> list = customerInfoService.selectCustomerInfoListHindrances(customerInfo);
        return AjaxResult.success(list);
    }


    @GetMapping("/listPermissionXi")
    public TableDataInfo listPermissionXi(CustomerInfo customerInfo)
    {
        startPage();
        List<CustomerInfo> list = customerInfoService.selectCustomerInfoListPermission(customerInfo);
        return getDataTable(list);
    }

    /**
     * 查询客户数据列表
     */
//    @PreAuthorize("@ss.hasPermi('system:customerData:list')")
    @GetMapping("/listNoPage")
    public AjaxResult listNoPage(CustomerInfo customerInfo)
    {

        List<CustomerInfo> list = customerInfoService.selectCustomerInfoList(customerInfo);
        return AjaxResult.success(list);
    }
    /**
     * 导出客户数据列表
     */
    @PreAuthorize("@ss.hasPermi('system:customerData:export')")
    @Log(title = "客户数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustomerInfo customerInfo)
    {
        List<CustomerInfo> list = customerInfoService.selectCustomerInfoList(customerInfo);
        ExcelUtil<CustomerInfo> util = new ExcelUtil<CustomerInfo>(CustomerInfo.class);
        util.exportExcel(response, list, "客户数据数据");
    }

    /**
     * 获取客户数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:customerData:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(customerInfoService.selectCustomerInfoById(id));
    }

    /**
     * 新增客户数据
     */
//    @PreAuthorize("@ss.hasPermi('system:customerData:add')")
    @Log(title = "客户数据", businessType = BusinessType.INSERT)
    @PostMapping("/insert")
    public AjaxResult insert(@RequestBody CustomerInfo customerInfo)
    {
        return toAjax(customerInfoService.insertCustomerInfo(customerInfo));
    }
    /**
     * 新增客户数据
     */
//    @PreAuthorize("@ss.hasPermi('system:customerData:add')")
    @Log(title = "客户数据", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult add(@RequestBody CustomerInfo customerInfo)
    {
        return toAjax(customerInfoService.insertCustomerInfo(customerInfo));
    }
    /**
     * 修改客户数据
     */
    @PreAuthorize("@ss.hasPermi('system:customerData:edit')")
    @Log(title = "客户数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerInfo customerInfo)
    {
        return toAjax(customerInfoService.updateCustomerInfo(customerInfo));
    }

    /**
     * 删除客户数据
     */
    @PreAuthorize("@ss.hasPermi('system:customerData:remove')")
    @Log(title = "客户数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(customerInfoService.deleteCustomerInfoByIds(ids));
    }
}
